package lty.pritace.staticnetwork;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageListener;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.apache.activemq.ActiveMQConnectionFactory;

/**
 * 点对点推送消息
 * 
 * @author lty
 *
 */
public class QR2 {
	public static void main(String[] args) throws Exception {
		ConnectionFactory cf = new ActiveMQConnectionFactory(
				// "tcp://localhost:61616");
				"tcp://192.168.233.128:61616");
		Connection connection = cf.createConnection();
		connection.start();

		final Session session = connection.createSession(Boolean.TRUE, Session.AUTO_ACKNOWLEDGE);
		Destination des = session.createQueue("my-queue");

		MessageConsumer consumer3 = session.createConsumer(des);
		consumer3.setMessageListener(new MessageListener() {

			public void onMessage(Message message) {
				// TODO Auto-generated method stub
				TextMessage msg = (TextMessage) message;
				try {
					System.out.println("qr2222===" + msg.getText());
					session.commit();
				} catch (JMSException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		});

	}
}
